<?php
namespace app\api\controller\xykeep;
use app\common\controller\Api;
use app\api\model\xykeep\Team as TeamModel;
use app\api\model\xykeep\User as UserModel;

/**
 * 战队
 */
class Team extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /*
     * 战队列表
     */
    public function lists()
    {
        $where = [
            'team.status' => 'normal'
        ];
        $lists = TeamModel::where($where)->with(['main'])->limit(0,9)->select();
        foreach ($lists as &$item) {
            $item['users'] = UserModel::where(['team_id'=>$item['id']])->field('id,nickname,avatar,xykeep_consume')->select();
            $item['total'] = UserModel::where(['team_id'=>$item['id']])->sum('xykeep_consume');
        }
        $this->success('战队列表',$lists);
    }

}